package com.enation.app.shop.front.api.commentlike.service.Impl;

import com.enation.app.shop.front.api.commentlike.entity.CommentLike;
import com.enation.app.shop.front.api.commentlike.service.ICommentLikeManager;
import com.enation.framework.database.IDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("/commentLikeService")
public class CommentLikeManager implements ICommentLikeManager {
    @Autowired
    private IDaoSupport daoSupport;
    @Override
    public int getCountLikeAndCommentAgain(Integer commentid,Integer temp) {
        String sql="";

        if (temp==1){
             sql="select count(*) from rbt_comment_like where comment_id=?  and  commentagain IS NOT NULL";
        }else {
             sql="select count(*) from rbt_comment_like where comment_id=?  and  status IS NOT NULL and status=1";
        }
        System.out.println(sql);
        return daoSupport.queryForInt(sql,commentid);
    }

    @Override
    public void updateStatus(Integer userid,Integer commentid,Integer status) {
        String sql="update rbt_comment_like set status=? where user_id=? and comment_id=?";
        this.daoSupport.execute(sql,status,userid,commentid);
    }

    @Override
    public void update(CommentLike commentLike) {
        this.daoSupport.update("rbt_comment_like",commentLike,"comment_like_id="+commentLike.getComment_like_id());
    }

    @Override
    public int create(CommentLike commentLike) {
        this.daoSupport.insert("rbt_comment_like",commentLike);
        //int creditid = this.daoSupport.getLastId("rbt_comment_like");
        return 1;
    }

    @Override
    public CommentLike getByUseridAndCommentId(Integer userid, Integer commentid,Integer goodsid) {
        String sql="select * from rbt_comment_like where user_id=?  and  comment_id=? and goods_id=?";
        CommentLike commentLike=this.daoSupport.queryForObject(sql,CommentLike.class,userid,commentid,goodsid);
        System.out.println(sql);
        return commentLike;
    }

    @Override
    public int count(Integer commentid) {
        String sql="select count(*) from rbt_comment_like where comment_id=? and status=1";
        int count=this.daoSupport.queryForInt(sql,commentid);
        return count;
    }

    @Override
    public List<CommentLike> getByCommentId(Integer commentid) {
        String sql="select * from rbt_comment_like where comment_id=?";
        List<CommentLike> commentLikes=daoSupport.queryForList(sql,CommentLike.class,commentid);
        return commentLikes;
    }
}
